import EmailBackend
import os.path


#People[Name] = Address
def EmailEvent(People, EventName, Message):
    f = open(os.path.relpath("Email\\EmailEventTemplate.txt"),'r')
    String = ''
    Done = False
    while not Done:
        try:
            Line = f.readline()
            if Line != "###END###":
                String += Line
            else:
                Done = True
        except:
            Done = True
    
    
    String = String.replace("""###Message###""", Message)
    Subject = """Email from the Cost Calculatorosorus regarding %s"""%EventName
    for Person in People.keys():
        Message = String.replace("""###Name###""", Person)
        
        EmailBackend.SendMessage(Message, People[Person], Subject)
        print Message
        
if __name__ == '__main__':
    P = {}
    P["James Collett"] = "jamesdcollett@gmail.com"
    EmailEvent(P,"Test Event","Hello Peps")